<?php

namespace app\service;

use app\model\NoteEntityRelationModel;
use app\tool\SingletonTrait;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;

class NoteEntityRelationService
{

    use SingletonTrait;
    /**
     * @param int $reviewFeedbackId
     * @return array|int[]
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function getAssetFeedbackAffectedShotCount(int $reviewFeedbackId): array
    {
        $data = NoteEntityRelationModel::join("relation_note_entity_relation", "note_entity_relation.id = relation_note_entity_relation.note_entity_relation_id")
            ->where('note_entity_relation.review_feedback_id', $reviewFeedbackId)
            ->where('note_entity_relation.relate_module_code', 'asset')
            ->field("count(DISTINCT relation_note_entity_relation.entity_id) as affected_shot_count")
            ->find();
        if (empty($data)) {
            return ['affected_shot_count' => 0];
        }
        return ['affected_shot_count' => $data['affected_shot_count']];
    }
}